const multer = require("@koa/multer");
const { UPLOAD_FILE_PATH } = require("../config/path");

// 上传文件中间件
const uploadFile = multer({
    storage: multer.diskStorage({
        destination: function (req, file, cb) {
            cb(null, `${UPLOAD_FILE_PATH}`);
        },
        filename: function (req, file, cb) {
            cb(null, `${Date.now()}_${file.originalname}`);
        },
    }),
});

// 头像上传中间件
const multerUploadAvatar = uploadFile.single("avatar");

module.exports = {
    multerUploadAvatar,
};
